home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: falstaff@xs4all.nl (Falstaff)
- Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
- Subject: Re: C coding problem
- Date: 6 Apr 1996 08:57:45 -0600
- Organization: XS4ALL, networking for the masses
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4k60p9$ahr@solutions.solon.com>
- References: <4j06na$808@solutions.solon.com> <4jttan$3gf@solutions.solon.com> <4jv6st$crf@solutions.solon.com> <4k1qh3$5hn@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
- X-Newsreader: NN version 6.5.0 #666 (NOV)
-
- news@Thinkage.On.CA writes:
-
- >In article <4jv6st$crf@solutions.solon.com> schwarz@mips.complang.tuwien.ac.at (Konrad Schwarz) writes:
- >>
- >>|> a[i] is converted to *(a + i) by the compiler in any case so
- >>|> whats the advantage with your approach?
- >>
- >>The machine doesn't have to add, the machine doesn't have to multiply,
- >>*a is less complicated to understand than a [i] since only one variable
- >>is involved, *a is more type safe than a [i], since there is nothing
- >>constraining i (besides it being of integral type), the optimizer
- >>has less to do, compile time decreases, etc.
-
- >However it is not always so that the machine does a distinct
- >add or multiply in order to handle a[i]. The "*p++" idiom may look
- >shot in the C code, and on a PDP-11 it usually resulted in nice
- >short code. However, there is no guarentee that this is true of all
- >hardware. It is not all that uncommon to have an architecture where
- >adding 1 to an int is much cheaper than adding one to a pointer,
-
- Name three.
-
- >In such and environment,
- > *q++ = *p++;
- >loses badly to
- > q[i] = p[i], ++i;
- >if the hardware indexing works in terms of the objects being
- >referenced.
-
- Even if you could name three such architectures, it doesn't mean
- that your 'winning' code loses on 99% of computers in the world.
- Besides, who (except for an absolute beginner) would code this:
-
- void loserstrcpy(char p[],char q[])
- { int i=0;
-
- while((q[i]=p[i])!=0)
- i++;
- }
-
- Frank
- --
- The famous GIICM now on line: http://www.xs4all.nl/~falstaff/GIICM.html
- ------------------------------------------------------------------------
- Frank A. Vorstenbosch +31-(70)-355 5241 falstaff@xs4all.nl
-